package cn.ckx.coding.moudle.user.dto;

import cn.ckx.coding.common.constant.SexEnum;
import cn.ckx.coding.common.validation.group.GroupCreate;
import cn.ckx.coding.moudle.user.entity.UserEntity;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.NonNull;
import org.springframework.beans.BeanUtils;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Null;
import java.io.Serializable;

/**
 * @ClassName UserDTO
 * @Description
 * @Author kunxin.cai
 * @Date 2021/2/26
 * @Version 1.0
 **/
@ApiModel(description = "用户")
@Data
public class UserDTO implements Serializable {

    private static final long serialVersionUID = 1L;

    @ApiModelProperty(value = "主键",hidden = true)
    @Null(groups = GroupCreate.class,message = "id为空")
    private String id;

    @ApiModelProperty("昵称")
    private String nickName;

    @ApiModelProperty("账号")
    private String accNumber;

    @NotNull
    @ApiModelProperty(value = "手机号",required = true)
    @NotBlank(groups = GroupCreate.class,message = "手机号码不能为空")
    private String mobile;

    @ApiModelProperty("性别")
    private SexEnum sex;

    public static UserDTO fromEntity(UserEntity userEntity){
        UserDTO user = new UserDTO();
        BeanUtils.copyProperties(userEntity,user);
        return user;
    }

    public static UserDTO fromEntity(UserEntity userEntity,UserDTO user){
        BeanUtils.copyProperties(userEntity,user);
        return user;
    }

    public UserEntity toEntity(){
        UserEntity userEntity = new UserEntity();
        BeanUtils.copyProperties(this, userEntity);
        return userEntity;
    }
}
